/*
 * UiBasicTestApp.cpp
 *
 *  Created on: 15/11/2011
 *      Author: Tales
 */

#include "UiBasicTestApp.hpp"
#include "core/Scene.hpp"
#include "core/Game.hpp"
#include "video/Screen.hpp"
#include "ui/ButtonBase.hpp"
#include "ui/CheckButton.hpp"
#include "ui/Label.hpp"
#include "ui/RadioButton.hpp"
#include "ui/ScrollableWindow.hpp"
#include "ui/SelectableWindow.hpp"
#include "ui/TextInput.hpp"
#include "ui/Window.hpp"

namespace yep
{

UiBasicTestApp UiBasicTestApp::instance;

UiBasicTestApp::UiBasicTestApp() :
		Application("ui/UiBasicTest", "A simple test")
{
	scene = NULL;
}

Scene & UiBasicTestApp::getFirstScene()
{
	if (!scene)
	{
		class UiBasicTestScene: public Scene
		{
			Label *label;
			ButtonBase *button;
		public:
			void setup(Game &game)
			{
				button = new ButtonBase("Sou um botão");
				button->setPosition({10,16});

				label = new Label("Sou uma Label");
				label->setPosition({10,32});

			}

			void cleanup(Game &game)
			{
				delete label;
			}

			void logic(Game &game)
			{
				SDL_Event event;
				while (SDL_PollEvent(&event))
				{
					if (event.type == SDL_QUIT)
						game.exit();
					else if (event.type == SDL_KEYDOWN)
					{
						switch (event.key.keysym.sym)
						{
						//EXIT
						case SDLK_ESCAPE:
							game.exit();
							break;
						default:
							label->onEvent(event);
							button->onEvent(event);
							break;
						}
					}
					else
					{
						label->onEvent(event);
						button->onEvent(event);
					}
				}
			}

			void draw(Game &game)
			{
				Screen &screen = Screen::getInstance();
				screen.clear(Color::LIGHT_GRAY);
				screen.fillRectangle(Vector2::ZERO, Vector2(screen.getWidth(), 8), Color::RED);
				string title = "Sprite Test";
				screen.drawText(Vector2(screen.getWidth() / 2 - title.size() * 4, 0), Color::LIGHT_YELLOW, title);

				//Draw Button
				button->onDraw(screen.getSurface());
				//Draw Label
				label->onDraw(screen.getSurface());
			}
		};
		scene = new UiBasicTestScene;
	}
	return *scene;
}

UiBasicTestApp::~UiBasicTestApp()
{
	// TODO Auto-generated destructor stub
	delete scene;
}

} /* namespace yep */
